﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ImageUploader.domain;
using System.DirectoryServices;

namespace ImageUploader.GUI
{
    public partial class ChooseOptionsForm : Form
    {
        private DomainController dc;

        public ChooseOptionsForm(LDAPConnection ldapConn)
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            InitializeComponent();
            dc = new DomainController(ldapConn);
        }

        private void btnEditUsers_Click(object sender, EventArgs e)
        {
            StaticMethods.ExecuteMethodShowLoading(delegate
            {
                this.lblLoading.Visible = true;
                this.Update();

                EditUsersForm euf = new EditUsersForm(dc);
                euf.Shown += new EventHandler(OtherForm_Shown);
                euf.FormClosed += new FormClosedEventHandler(other_FormClosed);
              //  this.BeginInvoke((MethodInvoker)delegate
              //  {
                    euf.Show(this);
                    this.lblLoading.Visible = false;
              //  });
            }, this);
        }

        private void OtherForm_Shown(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void other_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Show();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            ImportUsersForm iuf = new ImportUsersForm(dc);
            this.Hide();
            iuf.Show();
            iuf.FormClosed += new FormClosedEventHandler(other_FormClosed);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            StaticMethods.ExecuteMethodShowLoading(delegate
            {
                lblLoading.Visible = true;
                this.Update();
                ExportUsersForm euf = new ExportUsersForm(dc);
                euf.Shown += new EventHandler(OtherForm_Shown);
                euf.FormClosed += new FormClosedEventHandler(other_FormClosed);
                //  this.BeginInvoke((MethodInvoker)delegate
                //  {
                euf.Show(this);
                this.lblLoading.Visible = false;
                //  });
            }, this);
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            this.Close();
            GUIController.ShowLoginForm();
        }

        private void ChooseOptionsForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            //Application.Exit();
        }

    }
}
